<cpanel include="../../config.php">

<?

/***************************************************************************
 *                                 accounts.php
 *                            -------------------
 *   Begin                : Thursday, April 16, 2005
 *   Copyright            : (C) 2005 Point and Code
 *   Domain               : http://www.pointandcode.com/
 *   Email                : support@pointandcode.com
 *   Version              : 1.0.0
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

$html_root_path = '../../';
$page_title = "FTP Accounts";
include $root_path.'common.php';
include $root_path.'page_header.php';

$template->set_filenames(array(
	'body' => $root_path.$template_path.'ftp/accounts.tpl')
);



$ftp_accounts = <<<EOFpacman
<cpanel Ftp="listftpstable()">
EOFpacman;

$ftp_accounts = explode('</tr>', $ftp_accounts);
$array_of_ftp_accounts = array();

$i = 0;
foreach ($ftp_accounts as $row) {

	$is_custom = 0;
	$is_main = 0;

	// First, get the account name.
	$temp = explode('<font size = "2">', $row);
	$temp2 = explode('</font>', $temp[1]);
	$account_name = $temp2[0];
	
	// This account name possibly includes the URL of the ftp location - if not, it's a cpanel default. We need to figure this out...
	$account_name = str_replace("<b>", "", $account_name);
	$account_name = str_replace("</b>", "", $account_name);
	$temp2 = explode(' ', trim($account_name));
	if (!empty($temp2[1])) {
		// We have a custom account... So, get the URL.
		$is_custom = 1;
		$array_of_ftp_accounts[$i]['account'] = $temp2[0];
		
		/* With luck, we'll be able to grab the path of the ftp account from the middle of the <a href ... Cpanel, please don't change this! */
		$temp3 = explode('">', $temp2[2]);
		$temp3 = explode('</a>', $temp3[1]);

		$array_of_ftp_accounts[$i]['path'] = $temp3[0];

		
	} else {
		// This should be a main account, setup by cPanel.
		$is_main = 1;
		$array_of_ftp_accounts[$i]['account'] = $account_name;
	};

	$temp = explode('@', $array_of_ftp_accounts[$i]['account']);
	$array_of_ftp_accounts[$i]['start'] = $temp[0];
	$array_of_ftp_accounts[$i]['domain'] = $temp[1];


	if ($array_of_ftp_accounts[$i]['account'] != '') {
		$template->assign_block_vars('ftprow', array(
			'ROWCLASS' => ($i%2) ? $template_cfg['class_row_1'] : $template_cfg['class_row_2'],
			'ACCOUNT' => $array_of_ftp_accounts[$i]['account'],
			'PATH' => $array_of_ftp_accounts[$i]['path'],

			'U_CHANGE_PASS' => "accounts_change_password.php?account=".$array_of_ftp_accounts[$i]['start'],
			'U_DELETE' => "accounts_delete.php?account=".$array_of_ftp_accounts[$i]['start'],
			)
		);
		
		if ($is_main == 1) {
			$template->assign_block_vars('ftprow.switch_main_account', array());
		} else if ($is_custom == 1) {
			$template->assign_block_vars('ftprow.switch_custom_account', array());
		};

		$i++;
	};
};

$template->assign_vars(array(
	'S_ACTION' => "accounts_create_done.php",
));


//
// Woohoo! All done!
//
$template->pparse('body');




include $root_path.'page_tail.php';


?>